package service;

import dao.ClassDao;
import dao.ClassDaoImpl;
import dao.StudentDao;
import dao.StudentDaoImpl;
import entity.Clazz;
import entity.Result;
import entity.Student;

import java.util.List;

/**
 * @Author:SA
 * @DATA:DATA
 */


public class StudentServiceImpl implements  StudentService{
    private StudentDao studentDao= new StudentDaoImpl();
    private ClassDao classDao = new ClassDaoImpl();
    @Override
    public boolean addStudent(String id, String sname) {

        int i = studentDao.insertStudent(id, sname);
        return i>0;

    }

    @Override
    public boolean delStudent(String id) {
       int i= studentDao.delStudent(id);

        return i>0;
    }

    @Override
    public boolean divideClass(int stuNo, String className) {
        //1.根据班级的名称 查询班级的id
        Clazz clazz = classDao.selectByNname(className);
        long clazzid = clazz.getId();//班级编号
        //2根据学号更新学生的信息
        int line = studentDao.updateStudent(stuNo,clazzid);
        return  line>0;


    }

    @Override
    public List<Student> selectAll() {
        return   studentDao.selectAll();


    }
}
